'''
Created on Nov 8, 2009

@author: Nick Verbeck
'''
from PyQt4 import QtCore
import time

class FacebookLoginThread(QtCore.QThread):
    def __init__(self, facebookInst, fbLoggedInDialog):
        QtCore.QThread.__init__(self)
        self.finished = False
        self.facebook = facebookInst
        self.fbLoggedInDialog = fbLoggedInDialog
        
        self.connect(fbLoggedInDialog, QtCore.SIGNAL("loggedIn"), self._loggedIntoFacebook)
        
    def run(self):
        self.facebook.auth.createToken()
        self.facebook.login()
        
        while not self.finished:
            pass
            
        self.emit(QtCore.SIGNAL('loggedIn'))
            
    def _loggedIntoFacebook(self):
        self.facebook.auth.getSession()
        
        #print 'Session Key:   ', self.facebook.session_key
        #print 'Your UID:      ', self.facebook.uid
        
        self.finished = True
        
class FacebookFriendsThread(QtCore.QThread):
    def __init__(self, facebookInst):
        QtCore.QThread.__init__(self)
        self.facebook = facebookInst
        
    def run(self):
        friends = self.facebook.friends.get()
        friends = self.facebook.users.getInfo(friends, ['name', 'first_name', 'last_name', 
                                                             'birthday_date', 'current_location', 
                                                             'profile_url', 'website', 'email_hashes'])
        self.emit(QtCore.SIGNAL('gotFriends'), friends)